package com.sgcc.operate.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sgcc.common.datascope.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.operate.domain.OAttrField;
import com.sgcc.operate.service.IOAttrFieldService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * 规则属性字段Controller
 * 
 * @author sgcc
 * @date 2021-03-23
 */
@RestController
@RequestMapping("/attrfield")
public class OAttrFieldController extends BaseController
{
    @Autowired
    private IOAttrFieldService oAttrFieldService;

    /**
     * 查询规则属性字段列表
     */
    //@PreAuthorize(hasPermi = "operate:field:list")
    @GetMapping("/list")
    @DataScope(deptAlias = "")
    public TableDataInfo list(OAttrField oAttrField)
    {
        startPage();
        List<OAttrField> list = oAttrFieldService.selectOAttrFieldList(oAttrField);
        return getDataTable(list);
    }

    /**
     * 导出规则属性字段列表
     */
    //@PreAuthorize(hasPermi = "operate:field:export")
    @Log(title = "规则属性字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OAttrField oAttrField) throws IOException
    {
        List<OAttrField> list = oAttrFieldService.selectOAttrFieldList(oAttrField);
        ExcelUtil<OAttrField> util = new ExcelUtil<OAttrField>(OAttrField.class);
        util.exportExcel(response, list, "field");
    }

    /**
     * 获取规则属性字段详细信息
     */
    //@PreAuthorize(hasPermi = "operate:field:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(oAttrFieldService.selectOAttrFieldById(id));
    }

    /**
     * 新增规则属性字段
     */
    //@PreAuthorize(hasPermi = "operate:field:add")
    @Log(title = "规则属性字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OAttrField oAttrField)
    {
        return toAjax(oAttrFieldService.insertOAttrField(oAttrField));
    }

    /**
     * 修改规则属性字段
     */
    //@PreAuthorize(hasPermi = "operate:field:edit")
    @Log(title = "规则属性字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OAttrField oAttrField)
    {
        return toAjax(oAttrFieldService.updateOAttrField(oAttrField));
    }

    /**
     * 删除规则属性字段
     */
    //@PreAuthorize(hasPermi = "operate:field:remove")
    @Log(title = "规则属性字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oAttrFieldService.deleteOAttrFieldByIds(ids));
    }
}
